package parser

import (
	"demo02/crawler/engine"
	"demo02/crawler/models"
	"demo02/crawler/util"
	"regexp"
)

var ageRe = regexp.MustCompile(`<td><span class="label">年龄：</span>[\d]+岁</td>`)

var genderRe = regexp.MustCompile(`<td><span class="label">性别：</span><span field="">([^<]+)</span></td>`)
var heihtRe = regexp.MustCompile(`<td><span class="label">身高：</span>(\d+)CM</td>`)
var weightRe = regexp.MustCompile(`<td><span class="label">体重：</span><span field="">(\d+)KG</span></td>`)
var incomeRe = regexp.MustCompile(`<td><span class="label">月收入：</span>([^<]+)</td>`)
var marriageRe = regexp.MustCompile(`<td><span class="label">婚况：</span>([^<]+)</td>`)
var educationRe = regexp.MustCompile(`<td><span class="label">职业： </span>([^<]+)</td>`)
var occupationRe = regexp.MustCompile(`<td><span class="label">学历：</span>([^<]+)</td>`)
var hokouRe = regexp.MustCompile(`<td><span class="label">籍贯：</span>([^<]+)</td>`)
var xinzuoRe = regexp.MustCompile(`<td><span class="label">星座：</span>([^<]+)</td>`)
var houseRe = regexp.MustCompile(`<td><span class="label">住房条件：</span><span field="">([^<]+)</span></td>`)
var carRe = regexp.MustCompile(`<td><span class="label">是否购车：</span><span field="">([^<]+)</span></td>`)

func ParseProfile(content []byte, name string) engine.ParseRequest {
	profile := models.ProFile{}

	profile.Age = util.ExtractInt(content, ageRe)
	profile.Heiht = util.ExtractInt(content, heihtRe)
	profile.Weight = util.ExtractInt(content, weightRe)

	profile.Name = name
	profile.Gender = util.ExtractString(content, genderRe)
	profile.Income = util.ExtractString(content, incomeRe)
	profile.Marriage = util.ExtractString(content, marriageRe)
	profile.Education = util.ExtractString(content, educationRe)
	profile.Occupation = util.ExtractString(content, occupationRe)
	profile.Hokou = util.ExtractString(content, hokouRe)
	profile.Xinzuo = util.ExtractString(content, xinzuoRe)
	profile.House = util.ExtractString(content, houseRe)
	profile.Car = util.ExtractString(content, carRe)

	return engine.ParseRequest{
		Items: []interface{}{
			profile,
		},
	}
}
